home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Metrowerks Versions / C04 Speech / P04 Resource Speech / ResourceSpeech.c next >
Encoding:
C/C++ Source or Header  |  1995-08-30  |  2.9 KB  |  131 lines  |  [TEXT/MMCC]

  1. //____________________________________________________________
  2. //    ResourceSpeech.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Gestalt.h>
  13. #include <Speech.h>
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void     InitializeToolbox( void );
  19. Boolean  IsSpeechAvailable( void );
  20. void     OpenSpeechDialog( void );
  21. OSErr    SpeakOneString( Str255 );
  22.  
  23.  
  24. //____________________________________________________________
  25.  
  26. #define         rSpeechDialog          128
  27. #define         kSpeakShortButton        1
  28. #define         kSpeakLongButton         2
  29. #define         kQuitButton              3
  30. #define         rStringList            128
  31. #define         kShortStrIndex           1
  32. #define         kLongStrIndex            2
  33.  
  34.  
  35. //____________________________________________________________
  36.  
  37. void  main( void )
  38.    Boolean  speechPresent;
  39.  
  40.    InitializeToolbox();
  41.  
  42.    speechPresent = IsSpeechAvailable();
  43.    if ( speechPresent == false )
  44.       ExitToShell();
  45.  
  46.    OpenSpeechDialog();
  47. }
  48.  
  49.  
  50. //____________________________________________________________
  51.  
  52. void  OpenSpeechDialog( void )
  53. {
  54.    DialogPtr  theDialog;
  55.    short      theItem;
  56.    Boolean    allDone = false;
  57.    Str255     theString;
  58.    OSErr      theError;
  59.    
  60.    theDialog = GetNewDialog( rSpeechDialog, nil, (WindowPtr)-1L );
  61.    ShowWindow( theDialog );
  62.    SetPort( theDialog );
  63.    
  64.    while ( allDone == false )
  65.    {
  66.       ModalDialog( nil, &theItem );
  67.          
  68.       switch ( theItem )
  69.       {
  70.          case kSpeakShortButton:
  71.             GetIndString( theString, rStringList, kShortStrIndex ); 
  72.             theError = SpeakString( theString );
  73.             if ( theError != noErr )
  74.                ExitToShell();
  75.             break;
  76.  
  77.          case kSpeakLongButton:
  78.             GetIndString( theString, rStringList, kLongStrIndex ); 
  79.             theError = SpeakString( theString );
  80.             if ( theError != noErr )
  81.                ExitToShell();
  82.             break;
  83.  
  84.          case kQuitButton:
  85.             allDone = true;
  86.             break;
  87.       }
  88.    }
  89.    
  90.    DisposeDialog( theDialog ); 
  91. }
  92.  
  93.  
  94. //____________________________________________________________
  95.  
  96. Boolean  IsSpeechAvailable( void )
  97. {
  98.    OSErr    theError;
  99.    long     theResult;
  100.    Boolean  speechAvail;
  101.    
  102.    theError = Gestalt( gestaltSpeechAttr, &theResult );
  103.    if ( theError != noErr )
  104.       ExitToShell();
  105.       
  106.    speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );  
  107.    if ( speechAvail > 0 )
  108.       return ( true );
  109.    else
  110.       return ( false );
  111. }
  112.  
  113.  
  114. //____________________________________________________________
  115.  
  116. void  InitializeToolbox( void )
  117. {
  118.    InitGraf( &qd.thePort );
  119.    InitFonts();
  120.    InitWindows();
  121.    InitMenus();
  122.    TEInit();
  123.    InitDialogs( 0L );
  124.    FlushEvents( everyEvent, 0 );
  125.    InitCursor();
  126. }
  127.  
  128.  
  129.  
  130.